import 'package:flutter/material.dart';

class NikuEdgeInsets {
  double? top;
  double? left;
  double? bottom;
  double? right;

  NikuEdgeInsets({
    this.top,
    this.left,
    this.bottom,
    this.right,
  });

  factory NikuEdgeInsets.only({
    double? top,
    double? left,
    double? bottom,
    double? right,
  }) =>
      NikuEdgeInsets(
        top: top,
        left: left,
        bottom: bottom,
        right: right,
      );

  factory NikuEdgeInsets.all(double value) => NikuEdgeInsets(
        top: value,
        left: value,
        bottom: value,
        right: value,
      );

  factory NikuEdgeInsets.symmetric({
    double? horizontal,
    double? vertical,
  }) =>
      NikuEdgeInsets(
        top: vertical,
        left: horizontal,
        bottom: vertical,
        right: horizontal,
      );

  static const EdgeInsets zero = EdgeInsets.only();

  set pt(double padding) => top = padding;
  set pl(double padding) => left = padding;
  set pb(double padding) => bottom = padding;
  set pr(double padding) => right = padding;

  set px(double padding) {
    left = padding;
    right = padding;
  }

  set py(double padding) {
    top = padding;
    bottom = padding;
  }

  set p(double padding) {
    top = padding;
    left = padding;
    bottom = padding;
    right = padding;
  }

  EdgeInsets get value => EdgeInsets.only(
        top: top ?? 0,
        left: left ?? 0,
        bottom: bottom ?? 0,
        right: right ?? 0,
      );

  NikuEdgeInsets get copied => NikuEdgeInsets(
        top: top,
        left: left,
        bottom: bottom,
        right: right,
      );

  set apply(NikuEdgeInsets? v) {
    if (v == null) return;

    top = v.top ?? top;
    left = v.left ?? left;
    bottom = v.bottom ?? bottom;
    right = v.right ?? right;
  }
}

extension TransformNikuEdgeInsets on EdgeInsetsGeometry {
  NikuEdgeInsets get asNiku => NikuEdgeInsets(
        top: (this as EdgeInsets).top,
        left: (this as EdgeInsets).left,
        bottom: (this as EdgeInsets).bottom,
        right: (this as EdgeInsets).right,
      );
}
